package thread.xianchengfengbixing;

public class Client {

    public static void  main(String[] args){
        PeopleFoodManger peopleFoodManger = new PeopleFoodManger();


        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
               People people = new People();
               people.setName("sfy1");
               people.setFoodNums(100);
               peopleFoodManger.setPeopleThreadLocal(people);
                try {
                    Thread.currentThread().sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                People people1 = peopleFoodManger.getPeople();
                int num1 =0;
                for(int i=0;i<100;i++){
                    num1 = people1.foodNumsAdd();
                }
                System.out.println("当前线程名称:"+Thread.currentThread().getName()+"people对象:"+num1);
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                People people = new People();
                people.setName("sfy2");
                people.setFoodNums(200);
                peopleFoodManger.setPeopleThreadLocal(people);
                try {
                    Thread.currentThread().sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                People people2 = peopleFoodManger.getPeople();
                int num2 =0;
                for(int i=0;i<100;i++){
                    num2 = people2.foodNumsAdd();
                }
                System.out.println("当前线程名称:"+Thread.currentThread().getName()+"people对象:"+num2);

            }

        });
        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                People people = new People();
                people.setName("sfy3");
                peopleFoodManger.setPeopleThreadLocal(people);
                try {
                    Thread.currentThread().sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
             People people3 = peopleFoodManger.getPeople();
                people3.setFoodNums(300);
                int num3 =0;
                for(int i=0;i<100;i++){
                     num3 = people3.foodNumsAdd();
                }
                System.out.println("当前线程名称:"+Thread.currentThread().getName()+"people对象:"+num3);

            }
        });

        thread1.start();
        thread2.start();
        thread3.start();

    }
}
